home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / freeWAIS-sf-1.1 / ui / util.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-04  |  3.3 KB  |  157 lines

  1. /* 
  2.   WIDE AREA INFORMATION SERVER SOFTWARE:
  3.    No guarantees or restrictions.  See the readme file for the full standard
  4.    disclaimer.
  5.  
  6.    This is part of the shell user-interface tools for the WAIS software.
  7.    Do with it as you please.
  8.  
  9.    jonathan@Think.COM
  10. */
  11.  
  12. /* Copyright (c) CNIDR (see ../COPYRIGHT) */
  13.  
  14.  
  15. /* $Log: util.c,v $
  16.  * Revision 1.2  1994/08/05  07:30:19  pfeifer
  17.  * Release beta 04
  18.  *
  19.  * Revision 1.1  93/06/23  20:02:22  warnock
  20.  * Initial revision
  21.  * 
  22.  * Revision 1.1  1993/02/16  15:09:27  freewais
  23.  * Initial revision
  24.  *
  25.  * Revision 1.13  92/03/17  14:32:21  jonathan
  26.  * Generally cleaned up.
  27.  * 
  28.  * Revision 1.12  92/03/08  09:17:48  jonathan
  29.  * Fixed strip_lf.
  30.  * 
  31.  * Revision 1.11  92/03/08  09:12:33  jonathan
  32.  * Added new function, strip_lf.
  33.  * 
  34.  */
  35.  
  36. #ifndef lint
  37. static char *RCSid = "$Header: /usr/local/ls6/src+data/src/freeWAIS-sf/ui/RCS/util.c,v 1.2 1994/08/05 07:30:19 pfeifer Exp $";
  38. #endif
  39.  
  40. #define _C_UTIL
  41.  
  42. #include "wais.h"
  43. #include "globals.h"
  44.  
  45. int charlistlength(list)
  46. char **list;
  47. {
  48.   int num;
  49.  
  50.   if(list) {
  51.     for(num = 0; list[num] != NULL; num++);
  52.     return num;
  53.   }
  54.   else 
  55.     return 0;
  56. }
  57.  
  58. int listlength(list)
  59. List list;
  60. {
  61.   int num;
  62.   List l;
  63.  
  64.   for(num = 0, l = list; l != NULL; num++, l = l->nextNode);
  65.  
  66.   return num;
  67. }
  68.  
  69. #define BEFORE 1
  70. #define DURING 2
  71. #define QUOTE 5
  72.  
  73. /* ripped out of gmacs-ui.c */
  74. int find_string_slot(source, key, value, value_size, delete_internal_quotes)
  75. char *source, *key, *value;
  76. long value_size;
  77. Boolean delete_internal_quotes;
  78. {
  79.   char ch;
  80.   short state = BEFORE;
  81.   long position = 0;  /* position in value */
  82.   char *pos =(char*)strstr(source, key); /* address into source */
  83.  
  84.   value[0] = '\0';        /* initialize to nothing */
  85.  
  86.   if(NULL == pos)
  87.     return(1);
  88.  
  89.   for(pos = pos + strlen(key); pos < source + strlen(source); pos++){
  90.     ch = *pos;
  91.     if((state == BEFORE) && (ch == '\"'))
  92.       state = DURING;
  93.     else if ((state == DURING) && (ch == '\\')){
  94.       state = QUOTE;    
  95.       if(!delete_internal_quotes){
  96.     value[position] = ch;
  97.     position++;
  98.     if(position >= value_size){
  99.       value[value_size - 1] = '\0';
  100.       return(-1);
  101.     }
  102.       }
  103.     }
  104.     else if ((state == DURING) && (ch == '"')){    
  105.       value[position] = '\0';
  106.       return(0);
  107.     }
  108.     else if ((state == QUOTE) || (state == DURING)){
  109.       if(state ==  QUOTE)
  110.     state = DURING;
  111.       value[position] = ch;
  112.       position++;
  113.       if(position >= value_size){
  114.     value[value_size - 1] = '\0';
  115.     return(-1);
  116.       }
  117.     }
  118.     /* otherwise we are still before the start of the value */
  119.   }
  120.   value[position] = '\0';
  121.   return(-1); /* error because we are in the middle of the string */
  122. }
  123.  
  124. void find_value(source, key, value, value_size)
  125. char *source, *key, *value;
  126. int value_size;
  127. {
  128.   char ch;
  129.   long position = 0;  /* position in value */
  130.   char *pos =(char*)strstr(source, key); /* address into source */
  131.  
  132.   value[0] = '\0';        /* initialize to nothing */
  133.  
  134.   if(NULL == pos)
  135.     return;
  136.  
  137.   pos = pos + strlen(key);
  138.   ch = *pos;
  139.   /* skip leading quotes and spaces */
  140.   while((ch == '\"') || (ch == ' ')) {
  141.     pos++; ch = *pos;
  142.   }
  143.   for(position = 0; pos < source + strlen(source); pos++){
  144.     if((ch = *pos) == ' ') {
  145.       value[position] = '\0';
  146.       return;
  147.     }
  148.     value[position] = ch;
  149.     position++;
  150.     if(position >= value_size){
  151.       value[value_size - 1] = '\0';
  152.       return;
  153.     }
  154.   }
  155.   value[position] = '\0';
  156. }
  157.